package com.tang.mybatis.executor.parameter;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author Tang
 * @classname DefaultParameterHandler
 * @description [  ]
 * @date 2022/4/8 22:23
 */
public class DefaultParameterHandler implements ParameterHandler {

    private Object parameter;

    public DefaultParameterHandler(Object parameter) {
        this.parameter = parameter;
    }

    @Override
    public void setParameters(PreparedStatement preparedStatement) {
        if (null != parameter && parameter.getClass().isArray()) {
            Object[] params = (Object[]) parameter;
            for (int i = 0; i < params.length; i++) {
                try {
                    preparedStatement.setObject(i+1,params[i]);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}